# 'Author :Baolong Wang'
#'Created on 2019/6/29'
#导库

import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
from sklearn.tree import DecisionTreeRegressor
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestRegressor
from sklearn.metrics.regression import mean_squared_error, r2_score
#读入处理过得excel

df=pd.read_excel('./total.xls')
x_col_list=['A'+str(x) for x in range(1,21)]
X=df[x_col_list].values
y=df['Class'].values
#决策森林监督学习

X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.4,random_state=1)
forest = RandomForestRegressor(n_estimators=1000,criterion='mse',random_state=1,n_jobs=1)
forest.fit(X_train,y_train)
y_train_pred = forest.predict(X)
#计算匹配度
n=0
for _x,_y in zip(y,y_train_pred):
    _y=0 if _y<=5000 else 10000
    if _x==_y:
        n+=1
print('Total predicted  is %s,But %s is filled!'%(n,1000-n))
print('So the data matching rate is %.3f'%(n/1000))
